<?php
namespace Common\Model;
use Think\Model;
class LivePushOperatorModel extends VRLiveModel
{
	protected $autoCheckFields = false;
	
	protected $_validate = array(
			array('real_name', 'require', '姓名不能为空！', 0, 'regex', CommonModel:: MODEL_BOTH  ),
			array('mobile_phone', 'require', '账号不能为空！', 0, 'regex', CommonModel:: MODEL_BOTH  ),
			array('mobile_phone','','手机号已经存在！',0,'unique',CommonModel:: MODEL_BOTH ), // 验证mobile字段是否唯一
			array('mobile_phone','/^(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/', '手机号码有误！', -6, self::EXISTS_VALIDATE),
			array('password', 'require', '密码不能为空！', 0, 'regex', CommonModel:: MODEL_BOTH)
	);
	
	protected $_auto = array(
			array('create_time','mGetDate',CommonModel:: MODEL_INSERT,'callback'),
	);
	
	//用于获取时间，格式为2012-02-03 12:12:12,注意,方法不能为private
	function mGetDate() {
		return date('Y-m-d H:i:s');
	}
	
	public function queryLivePushOperatorList($status = -1, $name = null, $mobile_phone = null, $pageStart, $pageSize){
		$where = array();
		if(-1 != $status){
			$where['status'] = array('EQ', $status);
		}else {
			//2 为删除
			$where['status'] = array('NEQ', 2);
		}
		if($name && !empty($name)){
			$where['real_name'] = array('like','%'.$name.'%');
		}
		
		if($mobile_phone && !empty($mobile_phone)){
			$where['mobile_phone'] = array('like','%'.$mobile_phone.'%');
		}
		
		$list = $this->where($where)->limit($pageStart, $pageSize)->select();
		return $list;
	}
	
	public function queryLivePushOperatorCount($status = -1, $name = null, $mobile_phone = null){
		$where = array();
		if(-1 != $status){
			$where['status'] = array('EQ', $status);
		}
	    if($name && !empty($name)){
			$where['real_name'] = array('like','%'.$name.'%');
		}
		
		if($mobile_phone && !empty($mobile_phone)){
			$where['mobile_phone'] = array('like','%'.$name.'%');
		}
		return $this->where($where)->count();
	}
	
	public function getLivePushOperatorList(){
		$list = $this->where(array('status'=>1))->select();
		return $list;
	}
}

